﻿
namespace Model.CustomDataType
{
    public class CMDateTime : System.MarshalByRefObject
    {
        public const int YYYYMMDD = 1;
        private int day;
        private int month;
        private int year;

        private int hour;
        private int minute;
        private int second;
        public CMDateTime()
        {
            day = 1;
            month = 1;
            year = 2013;
            hour = 0;
            minute = 0;
            second = 0;
        }
        public CMDateTime(int day, int month, int year)
        {
            this.day = day;
            this.month = month;
            this.year = year;
            this.hour = 0;
            this.minute = 0;
            this.second = 0;
        }
        public CMDateTime(int day, int month, int year, int hour, int minute, int second)
        {
            this.day = day;
            this.month = month;
            this.year = year;
            this.hour = hour;
            this.minute = minute;
            this.second = second;
        }
        public int getDay()
        {
            return day;
        }

        public void setDay(int day)
        {
            this.day = day;
        }

        public int getMonth()
        {
            return month;
        }

        public void setMonth(int month)
        {
            this.month = month;
        }

        public int getYear()
        {
            return year;
        }

        public void setYear(int year)
        {
            this.year = year;
        }

        public int getHour()
        {
            return hour;
        }

        public void setHour(int hour)
        {
            this.hour = hour;
        }

        public int getMinute()
        {
            return minute;
        }

        public void setMinute(int minute)
        {
            this.minute = minute;
        }

        public int getSecond()
        {
            return second;
        }

        public void setSecond(int second)
        {
            this.second = second;
        }
        public string toString(int dateFormat)
        {
            string strMonth = month + "";
            string result = "";
            string strDay = day + "";
            string strHour = hour + "";
            string strMinute = minute + "";
            string strSecond = second + "";
            if (month >= 1 && month <= 9)
                strMonth = "0" + month;
            if (day >= 1 && day <= 9)
                strDay = "0" + day;
            if (hour >= 0 && hour <= 9)
                strHour = "0" + hour;
            if (minute >= 0 && minute <= 9)
                strMinute = "0" + minute;
            if (second >= 0 && second <= 9)
                strSecond = "0" + second;
            switch(dateFormat)
            {
                case YYYYMMDD:
                    result = year + "-" + strMonth + "-" + strDay + " " + strHour + ":" + strMinute + ":" + strSecond;
                    break;
                default:
                    result = strDay + "-" + strMonth + "-" + year + " " + strHour + ":" + strMinute + ":" + strSecond;
                    break;

            }
            
            return result;
        }
        public string toShortDateString()
        {
            string strMonth = month + "";
            string strDay = day + "";
            if (month >= 1 && month <= 9)
                strMonth = "0" + month;
            if (day >= 1 && day <= 9)
                strDay = "0" + day;
            return strDay + "/" + strMonth + "/" + year;
        }
        public string toShortTimeString()
        {
            string strHour = hour + "";
            string strMinute = minute + "";
            string strSecond = second + "";
            if (hour >= 1 && hour <= 9)
                strHour = "0" + hour;
            if (minute >= 1 && minute <= 9)
                strMinute = "0" + minute;
            if (second >= 1 && second <= 9)
                strSecond = "0" + second;
            return strHour + ":" + strMinute + ":" + strSecond;
        }
    }
}
